package controller

import (
	"advertising/internal/app/web/service"

	"192.168.1.75/go-pkg/errorx"
	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

type PromotionCount struct{}

// Increase 推广计数
func (PromotionCount) Increase(c *gin.Context) {
	var params struct {
		PromotionID string `json:"promotion_id"`
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	service.PromotionCount{}.Increase(c.Request.Context(), params.PromotionID)
	response.JSON(c, nil, nil)
}

// GetName 获取推广名称
func (PromotionCount) Detail(c *gin.Context) {
	detail, _ := service.PromotionCount{}.Detail(c.Request.Context(), c.Query("promotion_id"))
	if detail == nil {
		response.JSON(c, nil, errorx.New("获取推广详情失败", -1))
		return
	}
	response.JSON(c, gin.H{
		"name":   detail.Name,
		"app_id": detail.AppID,
		"uri":    detail.URI,
		"params": detail.Params,
	}, nil)
}
